package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_server.readteacher_server;

import com.alibaba.fastjson.JSON;

@WebServlet("/read_teacherServlet")
public class read_teacherServlet extends HttpServlet {
	readteacher_server server1 = new readteacher_server();
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String type = req.getParameter("type");
		readteacher_server stu = new readteacher_server();
		String json;
		try
		{
			int a=-1;
			if(type.equals("1")){
				json = JSON.toJSONString(stu.seekteacher());
				PrintWriter print = resp.getWriter();
				print.write(json);
			}
			if(type.equals("2")){
				String tId = req.getParameter("tId");
				String classId = req.getParameter("classId");
				String subId = req.getParameter("subId");
				a=stu.addteacher_server(tId,classId,subId);
				PrintWriter writer = resp.getWriter();
				writer.print(a);
			}
			
		} catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
